package com.hypo.controller;

import com.hypo.pojo.Category;
import com.hypo.pojo.Result;
import com.hypo.service.CategoryService;
import lombok.RequiredArgsConstructor;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/category")
@RequiredArgsConstructor
public class CategoryController {
    private final CategoryService categoryService;

    /**
     * 查询
     * @return 返回
     */
    @GetMapping
    public Result list() {
        List<Category> all = categoryService.list();
        if(CollectionUtils.isEmpty(all)){
            return Result.error("查询错误");
        }
        return Result.success(categoryService.find(all));
    }
}
